package com.ruoyi.warning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.warning.domain.dto.EncodeDTO;
import com.ruoyi.warning.domain.entity.Camera;
import com.ruoyi.warning.domain.entity.Encode;
import com.ruoyi.warning.domain.query.EncodeQuery;
import com.ruoyi.warning.mapper.EncodeMapper;
import com.ruoyi.warning.service.ICameraService;
import com.ruoyi.warning.service.ICameraSettingService;
import com.ruoyi.warning.service.IEncodeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 硬盘录像机表 服务实现类
 * </p>
 *
 * @author chenhc
 * @since 2025-09-30
 */
@Service
public class EncodeServiceImpl extends ServiceImpl<EncodeMapper, Encode> implements IEncodeService {
    @Resource
    private ICameraSettingService cameraSettingService;
    @Resource
    private ICameraService cameraService;
    @Override
    public List<EncodeDTO> tree(EncodeQuery query) {
        List<EncodeDTO> list = new ArrayList<>();
        List<Encode> encodeList = this.list(new LambdaQueryWrapper<>(Encode.class)
                .eq(query.getSettingId()!=null, Encode::getSettingId,query.getSettingId()));
        for(Encode encode:encodeList){
            EncodeDTO encodeDTO = new EncodeDTO();
            List<Camera> cameraList = cameraService.list(new LambdaQueryWrapper<Camera>()
                    .eq(Camera::getParentIndexCode,encode.getIndexCode()));
            BeanUtils.copyProperties(encode,encodeDTO);
            encodeDTO.setCameraList(cameraList);
            list.add(encodeDTO);
        }
        return list;
    }
}
